//
//  Explore_FeedBackViewController.swift
//  NewsItem
//
//  Created by mac on 2023/8/9.
//  Copyright © 2023 Kaka. All rights reserved.
//

import UIKit

class Explore_FeedBackViewController: BasicViewController {

    let iconImg = UIImageView.initImgView(img: "emailbig")
    let descl = UILabel.initV(.setTypeFace(16,type: .bold), text: "If you have any questions, you can contact Customer service email, we will get in touch with you as soon as possible.", textColor:UIColor.white)
    let titlefiled = UITextField.init(frame: .zero)
    let doneB = UIButton.initV(font: .setTypeFace(23, type: .bold), text: "Submit", img: "",contentMent: .center)

    private lazy var descView: Custom_TextView = {
        let view = Custom_TextView()
        view.backgroundColor = .clear
        view.textContainerInset = UIEdgeInsets(top: 10.Fit, left: 10.Fit, bottom: 10.Fit, right: -10.Fit)
        view.tintColor = .white
        view.textColor = .white
        view.placeHolderColor = UIColor.init(white: 1, alpha: 0.3)
        view.placeHolder = "Describe the problem you encountered in detail sothat we can deal with it as soon as possible. "
        view.returnKeyType = .done
        view.font = .setTypeFace(15,type: .medium)
        view.setAllCorners(corner: 25.Fit)
        return view
    }()

    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.isHidden = false
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "Feedback"
        view.subviews {
            iconImg
            descl
            titlefiled
            descView
            doneB
        }
        
        iconImg.size(130.Fit).top(30.Fit + NavHeight)
        iconImg.centerHorizontally()
        
        descl.left(30.Fit).right(30.Fit).height(65.Fit)
        descl.numberOfLines = 0
        descl.textAlignment = .center
        descl.Top == iconImg.Bottom + 10.Fit
        
        titlefiled.left(15.Fit).right(15.Fit).height(50.Fit)
        titlefiled.Top == descl.Bottom + 20.Fit
        titlefiled.setAllCorners(corner: 15.Fit)
        titlefiled.backgroundColor = .color(hexString: "#F1F1F1",alpha: 0.18)
        
        let attriText = NSMutableAttributedString.init(string: "Please enter your email address")
        attriText.addAttributes([NSAttributedString.Key.foregroundColor: UIColor.init(white: 1, alpha: 0.3)], range: NSRange(location: 0, length: attriText.string.count))
        titlefiled.attributedPlaceholder = attriText
        titlefiled.textColor = .white
        titlefiled.font = .setTypeFace(15,type: .medium)
        titlefiled.backgroundColor = .init(white: 1, alpha: 0.22)
        titlefiled.leftViewMode = .always
        let v1 = UIView.init(frame: .init(x: 0, y: 0, width: 50, height: 50))
        let img1 = UIImageView.initImgView(img: "iconEmal")
        img1.frame = .init(x: 15, y: 17, width: 20, height: 17)
        v1.addSubview(img1)
        titlefiled.leftView = v1

        descView.left(15.Fit).right(15.Fit).height(140.Fit)
        descView.Top == titlefiled.Bottom + 25.Fit
        descView.backgroundColor = .color(hexString: "#F1F1F1",alpha: 0.18)
        descView.setAllCorners(corner: 20.Fit)
        descView.contentInset = .init(top: 10, left: 0, bottom: 10, right: 0)
        
        doneB.backgroundColor = mainColor
        doneB.setTitleColor(.black, for: .normal)
        doneB.height(50).right(15).left(15).bottom(60.Fit)
        doneB.setAllCorners(corner: 25)
        
        doneB.addAct {
            guard self.titlefiled.text?.validateEmail() == true else {
                Toast_View_Tool.show(type: .error,text: "Invalid email address.")
                return
            }
            guard self.descView.text.count != 0 else {
                Toast_View_Tool.show(type: .error,text: "The suggestion cannot be empty")
                return
            }
            Toast_View_Tool.show()
            DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
                Toast_View_Tool.show(type: .success,text: "Thank you for your feedback!")
                self.navigationController?.popViewController(animated: true)
            }
            
        }
    }
        
}
